/*
https://leetcode-cn.com/problems/stone-game-ix/solution/shi-zi-you-xi-ix-by-leetcode-solution-kk5f/
 */
public class Solution2029 {
    public boolean stoneGameIX(int[] stones) {
        int c1=0,c2=0,c3=0;
        for (int stone : stones) {
            if (stone%3==0){
                c1++;
            }else if (stone%3==1){
                c2++;
            }else {
                c3++;
            }
        }
        return c1%2==0?(c2>=1 && c3>=1):(c2-c3>2 || c3-c2>2);
    }

    public static void main(String[] args) {
        System.out.println(new Solution2029().stoneGameIX(new int[]{5,1,2,4,3}));
    }
}
